package com.example.mymusicplayer;

import static com.example.mymusicplayer.MainActivity.musicFiles;

import android.graphics.Rect;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.io.ByteArrayOutputStream;

public class SongFragment extends Fragment {
        RecyclerView recyclerView;
        MusicAdapter musicAdapter;
    public SongFragment() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_song, container, false);
        recyclerView=view.findViewById(R.id.RecycleView);
        DividerItemDecoration dI = new DividerItemDecoration(view.getContext(), DividerItemDecoration.VERTICAL);
        recyclerView.addItemDecoration(dI);
        recyclerView.setHasFixedSize(true);

        if(!(musicFiles.size()<1)){
            Log.e("The Adapter is Trigger","ok!");
            System.out.println(musicFiles);
        musicAdapter =new MusicAdapter(getContext(),musicFiles);
        recyclerView.setAdapter(musicAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(),RecyclerView.VERTICAL,false));
        }
        else
        Log.e("The Adapter is Trigger","null");
        return view;
    }
    class MyItemDecoration extends RecyclerView.ItemDecoration {

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            //设定底部边距为1px
            outRect.set(1, 1, 1, 1);
        }
}
    }